//
//  PersonalEditInformationViewController.m
//  suRead
//
//  Created by 龚浩植 on 16/4/25.
//  Copyright © 2016年 bao. All rights reserved.
//

#import "PersonalEditInformationViewController.h"
#import "ChangePhoneView.h"
#import "Masonry.h"
#import "AccountManager.h"
#import "AppDelegate.h"
#import "UIApplication+VisibleViewController.h"

#import "PersonalEditInformationTableViewController.h"
static NSString *PersonalEditInformationTableViewControllerSegue = @"PersonalEditInformationTableViewControllerSegue";

@interface PersonalEditInformationViewController ()
@property (strong, nonatomic)ChangePhoneView *changePhoneView;
@property (strong, nonatomic)PersonalEditInformationTableViewController *controller;
@property (assign, nonatomic)BOOL iskeybord;
//@property (strong, nonatomic)UINavigationBar *mybar;

@end

@implementation PersonalEditInformationViewController
- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    __weak typeof(self) weka_self = self;
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillShow:)
                                                 name:UIKeyboardWillShowNotification
                                               object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillHide:)
                                                 name:UIKeyboardWillHideNotification
                                               object:nil];
    self.changePhoneView = [ChangePhoneView changePhoneView];
    [self.view addSubview:_changePhoneView];
    self.changePhoneView.center=CGPointMake(self.view.center.x,self.changePhoneView.center.y);
//    [_changePhoneView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.edges.equalTo(weka_self.changePhoneView.superview);
//    }];
//    weka_self.changePhoneView setrect
    weka_self.changePhoneView.hidden = YES;

    [self.changePhoneView setBaViewTapCallBackBlock:^{
        if (weka_self.iskeybord) {
            [weka_self.changePhoneView.phoneText resignFirstResponder];
            [weka_self.changePhoneView.codeText resignFirstResponder];
            [weka_self.changePhoneView.pwdText resignFirstResponder];
            weka_self.iskeybord = NO;
        }
        else
        {
            weka_self.changePhoneView.hidden = YES;
        }
        
    }];
    [self.changePhoneView setCallBackBlock:^{
        weka_self.changePhoneView.hidden = YES;
//        [[[UIApplication sharedApplication] visibleViewController].navigationController dismissViewControllerAnimated:YES completion:nil];
        [[[UIApplication sharedApplication] visibleViewController].navigationController popToRootViewControllerAnimated:YES];

    }];

    
    
    self.changePhoneView.title = @"绑定手机号";
    [self.changePhoneView setSuccessBlock:^{
        weka_self.controller.phoneTextField.text = [AccountManager sharedAccountManager].f_phone_num;
//        [weka_self.controller.phoneTextField addTarget:self action:@selector(editMyPhone:) forControlEvents:UIControlEventTouchUpInside];
        weka_self.changePhoneView.hidden = YES;
    }];

    self.controller.changePhoneView = self.changePhoneView;
    // Do any additional setup after loading the view.
    
   }
//
//- (IBAction)editMyPhone:(id)sender {
//    [self showAndEditPHONE];
//}
//
//-(void)showAndEditPHONE {
//    if ([AccountManager sharedAccountManager].f_phone_num.length) {
//        return;
//    }
//    self.changePhoneView.hidden = NO;
//    
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    if ([segue.identifier isEqualToString:PersonalEditInformationTableViewControllerSegue]) {
        self.controller = segue.destinationViewController;
    }
}
- (IBAction)goBack:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
    [self dismissViewControllerAnimated:YES completion:nil];

}

#pragma mark 键盘显示的监听方法
- (void) keyboardWillShow:(NSNotification *) note
{
    _iskeybord = YES;
}

#pragma mark 键盘隐藏的监听方法
- (void) keyboardWillHide:(NSNotification *) note
{
}


@end
